#!/bin/sh

if [ -n "$1" ]
then
	FSE_HOME="$1"
else
	##没有指定安装路径时，指定默认的路径 
	FSE_HOME="/usr/local/feature_se"
fi
mkdir_if_no_exist(){
	if [ $# -eq 1 ]
	then
		if [[ -d $1 ]]
		then
			return 0
			
		else
			##安装路径不存在时创建目录 
			mkdir $1
		fi
	else 
		echo invalid argument
		return -1
	fi
}
FSE_HOME_LIB="$FSE_HOME/bin"
if mkdir_if_no_exist $FSE_HOME && mkdir_if_no_exist $FSE_HOME_LIB
then
	echo "install to $FSE_HOME........................."
	src_path=$(cd "$(dirname "$0")"; pwd)
	cd "$(dirname "$0")"
	echo copy to $FSE_HOME
	chmod +x lib*
	cd ..
	cp -r * $FSE_HOME
	echo "$FSE_HOME_LIB">/etc/ld.so.conf.d/feature_se_lib.conf
	/sbin/ldconfig
	# modify /etc/profile,add FSE_HOME_LIB to PATH
	new_export="export PATH=$FSE_HOME_LIB:\$PATH"
	reg_str="^\s*export\s*PATH=$FSE_HOME_LIB:\$PATH"
	if grep -q $reg_str /etc/profile
	then
		echo $FSE_HOME_LIB exists in PATH,skip
	else
		echo defined PATH variable
		echo $new_export >> /etc/profile
	fi
	# display new line
	grep $reg_str /etc/profile
	echo variable PATH in /etc/profile updated	
	source /etc/profile		
	echo "install finished"
fi

